Skip to content

ci: scope permissions to jobs and fix workflow syntax#4066

Open
PatStLouis wants to merge 2 commits intoopenwallet-foundation:mainfrom
OpSecId:address-sonarqube-issues
Open

ci: scope permissions to jobs and fix workflow syntax#4066
PatStLouis wants to merge 2 commits intoopenwallet-foundation:mainfrom
OpSecId:address-sonarqube-issues

Conversation

@PatStLouis
Copy link
Contributor

Summary

Moves GitHub Actions permissions from workflow level to job level across workflows and fixes minor workflow syntax. No change in behavior; each job still has the permissions it needs.

Changes

  • Permissions: Removed workflow-level contents: read, pull-requests: read, and checks: write where present and set the same permissions on the jobs that use them (e.g. PR Tests, Nightly, Format, BDD integration/interop, Scenario integration, Sonar PR/merge, CodeQL, pip-audit, publish-docs, pythonpublish, Snyk). Write permissions (contents: write, packages: write) remain only on the jobs that need them (e.g. Tag and Recreate LTS, Publish).
  • Syntax: Replaced quoted "on": with on: in format.yml and codeql.yml.
  • Scorecard: Already using explicit contents: read and actions: read (no read-all).
  • Run integration tests action: TEST_SCOPE is passed via env instead of inline in the run script (addresses user-controlled data in run block).

Why

  • Aligns with GitHub/SonarQube guidance to use minimal, job-scoped permissions.
  • Keeps behavior the same: every job that needed a permission still has it at job level.

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
@sonarqubecloud
Copy link

@jamshale
Copy link
Contributor

Looks good to me.

Only thing I'm a bit concerned about is some of the workflows don't actually run unless there is source code changes so I'm unsure if they will be successful or not.

One way to test is to change the target repo and do a source code change in your fork. Or we can merge it and try some manual runs.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens GitHub Actions security by scoping GITHUB_TOKEN permissions to individual jobs (instead of workflow-wide defaults) and fixes a couple of workflow syntax details, aiming to keep behavior unchanged while reducing the permission footprint.

Changes:

  • Move workflow-level permissions into the specific jobs that require them across multiple CI workflows.
  • Replace quoted "on": with on: in select workflows.
  • Adjust the run-integration-tests composite action to pass TEST_SCOPE via env rather than interpolating into the run: block.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.github/workflows/tag-recreate-lts.yml Splits contents: write and packages: write permissions across the jobs that need them.
.github/workflows/sonar-pr.yml Moves Sonar PR scan permissions from workflow to job scope.
.github/workflows/sonar-merge-main.yml Moves Sonar merge-to-main permissions from workflow to job scope.
.github/workflows/snyk.yml Removes workflow-level permissions; relies on job-scoped permissions.
.github/workflows/snyk-lts.yml Removes workflow-level permissions; relies on job-scoped permissions.
.github/workflows/scorecard.yml Replaces read-all with explicit read permissions at workflow level.
.github/workflows/scenario-integration-tests.yml Moves PR/scenario integration workflow permissions to the job.
.github/workflows/pythonpublish.yml Moves contents: read into the publish job permissions alongside id-token: write.
.github/workflows/publish.yml Removes workflow-level contents: read (jobs already define needed permissions).
.github/workflows/publish-docs.yml Removes workflow-level contents: read (deploy job uses job-scoped contents: write).
.github/workflows/pr-tests.yml Moves PR test permissions to each job.
.github/workflows/pip-audit.yml Moves contents: read to the job.
.github/workflows/nightly.yml Moves Nightly workflow permissions down to each job / reusable workflow call.
.github/workflows/format.yml Fixes on: syntax and scopes permissions to the lint job.
.github/workflows/codeql.yml Fixes on: syntax and scopes contents: read to the CodeQL job.
.github/workflows/bdd-interop-tests.yml Moves workflow-level permissions to the test job.
.github/workflows/bdd-integration-tests.yml Partially moves permissions to the job, but retains workflow-level permission.
.github/actions/run-integration-tests/action.yml Passes TEST_SCOPE via env rather than inline expression expansion in run:.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to 13
permissions:
contents: read
pull-requests: read
checks: write
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions is still defined at the workflow level (currently checks: write). This keeps elevated permissions enabled for the entire workflow and is inconsistent with the stated goal of job-scoped least-privilege. Move/remove the workflow-level permissions block and keep checks: write only on the job(s) that require it.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is contradicting what sonarqube flagged

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Patrick St-Louis <43082425+PatStLouis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants